package com.etms.service;

import com.etms.mapper.AccountsMapper;
import com.etms.mapper.AccountsMsgMapper;
import com.etms.pojo.AccountMsg;
import com.etms.pojo.Accounts;
import com.etms.pojo.Repertory;
import com.etms.utils.DaochuUtils;
import com.etms.utils.DateUtils;
import com.etms.utils.IdUtils;
import com.etms.vo.PageParmas;
import com.etms.vo.PageResult;
import com.etms.vo.RepertoryVo;
import com.etms.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class AccountsService {
    @Autowired
    AccountsMapper accountsMapper;
    @Autowired
    AccountsMsgMapper accountsMsgMapper;
    public Accounts findById(int id) {
        return accountsMapper.findById(id);
    }

    public Integer updateMoney(Double premoney, Double nowmoney, Integer id) {
        return accountsMapper.updateMoney(premoney,nowmoney,id, DateUtils.getDateTime(new Date()));
    }

    public void insertMsg(AccountMsg accountMsg) {
        accountsMsgMapper.addOne(accountMsg);
    }

    public Result findALLMsg(PageParmas pageParmas) {
        PageHelper.startPage(pageParmas.getCurrentPage(), pageParmas.getPageSize());
        List<AccountMsg> list=accountsMsgMapper.findAll();
        PageInfo pageInfo=new PageInfo(list);
        PageResult pageResult=new PageResult();
        pageResult.setList(list);
        pageResult.setTotalPage(pageInfo.getPages());
        return Result.successed(pageResult);
    }

    public Result getPrice() {
        Double price = accountsMapper.findById(1).getPrice();
        return Result.successed(IdUtils.doubleToString(price));
    }

    public Result daochu() {
        List<AccountMsg> all = accountsMsgMapper.findAll();
        String daochuzhangdan = DaochuUtils.daochuzhangdanForExcel(all);
        return Result.successed("导出成功！导出信息文件存放于:"+daochuzhangdan,null);
    }
}
